<template>
  <el-dialog title="手动执行" v-model="visible" :width="600" destroy-on-close @closed="$emit('closed')">
    <el-form :model="form" :rules="rules" ref="dialogForm" label-width="80px">
      <el-form-item label="任务名称" prop="name">
		{{ form.name }}
      </el-form-item>
      <el-form-item label="参数列表" prop="param">
        <el-input v-model="form.param" placeholder="请输入参数列表" clearable type="textarea" :autosize="{ minRows:10, maxRows:30 }"></el-input>
		<span>参数必需是一个只有一级Key-Value的JSON结构, 且名称必需为字符串</span>
      </el-form-item>
      <el-form-item label="任务描述" prop="description">
        <el-input v-model="form.description" placeholder="请输入描述" readonly clearable type="textarea" :autosize="{ minRows:2, maxRows:6 }"></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button @click="visible=false" >取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">运 行</el-button>
    </template>

  </el-dialog>

</template>

<script>
    import setting from './setting'
	export default {
		emits: ['success', 'closed'],
		components: {
		},
		data() {
			return {
				mode: "add",
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					name: '',
					param: '',
					description: '',
					_: ""
				}
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(){
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res = await setting.api.run.post(this.form)
						this.isSaveing = false;
						if(res.code == setting.successCode){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				})
			},
			//表单注入数据
			setData(data){
				this.form.name = data.name
				this.form.param = data.param
				this.form.description = data.description

				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.form, data)
			}
		}
	}
</script>

<style>
</style>
